﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;

public partial class _Default : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public void leermensaje(object sender, EventArgs e)
    {

        String nombre = TextBox1.Text;
        MySqlConnection myConnection = new MySqlConnection();
        myConnection.ConnectionString = "Persist Security Info=False;Username=root;Password=;database=dad;server=localhost;Connect Timeout=30";
        myConnection.Open();
        var q = String.Format("SELECT * FROM mensajes WHERE para='{0}'",nombre);
        //var remitente="";
        //var mensaje="";
       
        //create command and assign the query and connection from the constructor
        MySqlCommand cmd = new MySqlCommand(q, myConnection);
       
        var cont = "<table><tbody>";

        MySqlDataReader dataReader = cmd.ExecuteReader();
        //Read the data and store them in the list
        while (dataReader.Read())
        {
            var remitente = dataReader["de"];
            var mensaje = dataReader["contenido"];
            var x = String.Format("<tr><td>{0}</td><td>{1}</td></tr>", remitente, mensaje);
            cont += x;

        }
        cont += "</table></tbody>";

        //close Data Reader
        dataReader.Close();
        //close Connection
         myConnection.Close();
        
        //"<table><tbody><td>{0}</td><td>{1}</td></tbody></table>"

        contenido.Text = cont;

    }


}